package main

import (
	"flag"
	"github.com/gin-gonic/gin"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"log"
	"shop/api/router"
	"shop/common/config"
	"shop/common/global"
	"shop/common/inits"
	"shop/shop_grpc/proto/shop"
	"shop/user_grpc/proto/user"
)

func main() {
	config.Init()
	inits.InitMysql()
	inits.InitRedis()
	inits.InitNacos()
	//inits.InitElasticsearch() // 初始化ES客户端
	Client()
	r := gin.Default()
	router.Load(r)
	r.Run()
}

func Client() {
	flag.Parse()
	// Set up a connection to the server.
	conn, err := grpc.NewClient("127.0.0.1:50051", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	global.ShopClient = shop.NewShopClient(conn)

	flag.Parse()
	// Set up a connection to the server.
	conns, err := grpc.NewClient("127.0.0.1:50052", grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}
	global.UserClient = user.NewUserClient(conns)
}
